package com.glory.brepda.activity.mfg;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.brepda.R;
import com.glory.brepda.adapter.GroupEqpListAdapter;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.EqpStatusEntity;
import com.glory.brepda.entity.ResponseMessageEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class RequestLotActivity extends BaseActivity {

    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.etEqpId)
    FreeUI_ClearEditText etEqpId;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.llMain)
    LinearLayout llMain;






    @Override
    protected int getLayoutResId() {
        return R.layout.activity_request_lot;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
        String title = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        tvTitle.setText(title);
        tvBaseSubmit.setText("查询");

    }

    @Override
    protected void initData() {
        initEdit(etEqpId, this::requestLot);
    }

    @OnClick({R.id.tvBaseSubmit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit: //提交按钮逻辑
                requestLot(getText(etEqpId));
        }
    }
    private void requestLot(String eqpID) {
        FreeUI_EntityCallBack<BaseResponseBean<ResponseMessageEntity>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<ResponseMessageEntity>>
                (new TypeToken<BaseResponseBean<ResponseMessageEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<ResponseMessageEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getApplicationContext(), true, getSupportFragmentManager())) {
                    ResponseMessageEntity entity = response.body().getResponse().getBody();
                    showConfirmDialog(entity.getMESSAGE());
//                    try {
//                        showConfirmDialog(jsonObject.getString("MESSAGE"));
//                    } catch (JSONException e) {
//                        e.printStackTrace();
//                    }
                }

            }

            @Override
            public void onError(Response<BaseResponseBean<ResponseMessageEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "WBMATCH");
            }
        };

        JsonObject map = new JsonObject();
        map.addProperty("EQUIPMENTID",eqpID);
        map.addProperty("ACTIONTYPE","REQUEST_LOT");
        NetUtils.requestPostNet("IF.WBMATCH","Common", RequestLotActivity.this,map,callBack);
    }

}
